package com.java46.carera.stock.outstock.controller;

import com.github.pagehelper.PageInfo;
import com.java46.carera.base.entity.FetchStorage;
import com.java46.carera.base.entity.JsonResult;
import com.java46.carera.base.entity.vo.FetchStorageVo;
import com.java46.carera.base.util.JsonUtil;
import com.java46.carera.stock.outstock.service.OutStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ClassName OutStockController
 * @Description TODO
 * @Author Administrator
 * @Date 2018/8/23 0023 19:42
 * @Vcrsion 1.0
 **/
@Controller
@RequestMapping("/stock/outstock")
public class OutStockController {

    @Autowired
    private OutStockService outStockService;


    /**
     * @Author xiao
     * @Description //分页查询出库记录可根据关键字
     * @Date 23:06 2018/8/23 0023
     * @Param [pagenum, pagesize, keywords]
     * @return com.java46.carera.base.entity.JsonResult
     */
    @RequestMapping("/queryoutstock")
    @ResponseBody
    public JsonResult queryOutStock(int pagenum, int pagesize, String keywords) throws Exception {

        PageInfo<FetchStorageVo> puStorageVoPageInfo = outStockService.queryOutStock(pagenum, pagesize, keywords);
        JsonResult jsonResult = JsonUtil.setJsonResult(true, "查询成功", puStorageVoPageInfo);

        return jsonResult;
    }

    /**
     * @Author xiao
     * @Description //新增出库记录
     * @Date 23:06 2018/8/23 0023
     * @Param [fetchStorage]
     * @return com.java46.carera.base.entity.JsonResult
     */
    @RequestMapping("/insertoutstock")
    @ResponseBody
    public JsonResult insertOutstock(FetchStorage fetchStorage) throws Exception {

        outStockService.insertOutStock(fetchStorage);
        JsonResult jsonResult = JsonUtil.setJsonResult(true, "新增成功", null);
        return jsonResult;
    }


    /**
     * @Author xiao
     * @Description //删除出库记录
     * @Date 23:06 2018/8/23 0023
     * @Param [fetid]
     * @return com.java46.carera.base.entity.JsonResult
     */
    @RequestMapping("/deleteoutstock")
    @ResponseBody
    public JsonResult deleteOutstock(Integer fetid) throws Exception {

        outStockService.deleteOutStock(fetid);
        JsonResult jsonResult = JsonUtil.setJsonResult(true, "删除成功", null);
        return jsonResult;
    }
}
